﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HAUtil;

namespace HA.ModFlow.Domain.DomainLayer
{

    /// <summary>
    /// 用于表示所有点状源汇的基类
    /// </summary>

    [Serializable]
   public class MFPointSC:MFBoundary
    {
        public MFPointSC(int i, int j, int k, int nrows, int ncolumns, int nlayers,int nPeriods):base(nrows,ncolumns,nlayers,nPeriods)
        {
            this._i = i;
            this._j = j;
            this._k = k; 
        }



        public MFPointSC(int index, int nrows, int ncolumns, int nlayers, int nPeriods)
            : base(nrows,ncolumns,nlayers,nPeriods)
        {

            this.Index = index;
                             
        }


        bool _isTransient = false;

        public bool IsTransient
        {
            get { return _isTransient; }
            set
            {
                _isTransient = value;
                
            }
        }


        

        public int Index
        {
            get {
                
                return this.GetIndex(this._i,this._j,this._k);
            
            }
            set
            {



              int[]  ijk=  this.GetIJK(value);

              this._i = ijk[0];
              this._j = ijk[1];
              this._k = ijk[2];
              

              
            }
        }

        int _i;

        public int I
        {
            get { return _i; }
            set
            {
                _i = value;
               
               
            }

        }
        int _j;

        public int J
        {
            get { return _j; }
            set
            {
                _j = value;
              
             
            }
        }
        int _k;

        public int K
        {
            get { return _k; }
            set
            {
                _k = value;
               

                
            }
        }


        #region 受保护的函数

        public virtual void OnResetSperiods(int nPeriods)
        {

 
        }

        #endregion

        #region 公共函数


        public int GetIndex(int i, int j, int k)
        {
            int index;
            int rowCount = this.RCount;
            int colCount = this.CCount;
            if (j == colCount)
            {
                index = rowCount * colCount * (k - 1) + i * j;
            }
            else
            {
                index = rowCount * colCount * (k - 1) + (i - 1) * colCount + j;
            }
            return index;
        }

        public int[] GetIJK(int index)
        {
            int rowCount = this.RCount;
            int colCount = this.CCount;
            int i, j, k;
            int m = index / (rowCount * colCount);
            int n = index % (rowCount * colCount);
            if (n == 0)
            {
                k = m;
                i = rowCount;
                j = colCount;
            }
            else
            {
                k = m + 1;
                if (n % colCount == 0)
                {
                    i = n / colCount;
                    j = colCount;
                }
                else
                {
                    i = n / colCount + 1;
                    j = n % colCount;
                }
            }
            int[] location =  { i, j, k } ;
            return location;
        }

        #endregion

    }
}
